package com.augurit.wf.client.agency.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.augurit.wf.client.agency.web.form.WfAgencyDetailForm;
import com.augurit.wf.common.entity.WfAgencyDetail;

public class WfAgencyDetailConvertor {
	public static WfAgencyDetailForm convertVoToForm(WfAgencyDetail entity) {
		if(entity != null) {
			WfAgencyDetailForm form = new WfAgencyDetailForm();
			form.setId(entity.getId());
			form.setAgencyId(entity.getAgencyId());
			form.setWfTemplateId(entity.getWfTemplateId());
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(WfAgencyDetailForm form, WfAgencyDetail entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			entity.setAgencyId(form.getAgencyId());
			if(form.getWfTemplateId() != null )
				entity.setWfTemplateId(form.getWfTemplateId());
		}
	}
	
	public static List<WfAgencyDetailForm> convertVoListToFormList(List<WfAgencyDetail> wfAgencyDetailList) {
		if(wfAgencyDetailList != null && wfAgencyDetailList.size() > 0) {
			List<WfAgencyDetailForm> wfAgencyDetailFormList = new ArrayList();
			for(int i=0; i<wfAgencyDetailList.size(); i++) {
				wfAgencyDetailFormList.add(convertVoToForm(wfAgencyDetailList.get(i)));
			}
			return wfAgencyDetailFormList;
		}
		return null;
	}
	
	public static List<Map> convertVoListToMapList(List<WfAgencyDetail> wfAgencyDetailList) {
		if(wfAgencyDetailList != null && wfAgencyDetailList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<wfAgencyDetailList.size(); i++) {
				WfAgencyDetail entity = wfAgencyDetailList.get(i);
				Map<String, String> map = new HashMap();

				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("agencyId", entity.getAgencyId() == null ? "" : entity.getAgencyId().toString());
				map.put("wfTemplateId", entity.getWfTemplateId().toString());
				
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<WfAgencyDetail> convertFormListToVoList(List<WfAgencyDetailForm> wfAgencyDetailFormList) {
		if(wfAgencyDetailFormList != null && wfAgencyDetailFormList.size() > 0) {
			List<WfAgencyDetail> wfAgencyDetailList = new ArrayList();
			for(int i=0; i<wfAgencyDetailFormList.size(); i++) {
				WfAgencyDetail wfAgencyDetail = new WfAgencyDetail();
				convertFormToVo(wfAgencyDetailFormList.get(i), wfAgencyDetail);
				wfAgencyDetailList.add(wfAgencyDetail);
			}
			return wfAgencyDetailList;
		}
		return null;
	}
}